package topcbl.adapter;

import java.util.List;

import topcbl.data.TaxiBrand;
import topcbl.taxi.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Adapter for quick call list taxi
 * 
 * @author baolong
 * 
 */
public class ListTaxiAdapter extends ArrayAdapter<TaxiBrand> {
	Context context;
	int layoutResourceId;
	List<TaxiBrand> data = null;

	public ListTaxiAdapter(Context context, int layoutResourceId,
			List<TaxiBrand> data) {
		super(context, layoutResourceId, data);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.data = data;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final HolderTaxiView holder;
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.row_quickcall_taxi, null);
			TextView tenHang = (TextView) convertView
					.findViewById(R.id.row_taxi_hang);
			TextView sdt = (TextView) convertView
					.findViewById(R.id.row_taxi_sdt);
			ImageView logoTaxi = (ImageView) convertView
					.findViewById(R.id.row_taxi_image);
			logoTaxi.setImageResource(data.get(position).getmLogoBrand());
			tenHang.setText(data.get(position).getmNameBrand());
			sdt.setText(data.get(position).getmPhoneNumber());
			holder = new HolderTaxiView();
			holder.brand = tenHang;
			holder.phone = sdt;
			holder.logo = logoTaxi;
			convertView.setTag(holder);
		}
		return convertView;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	public static class HolderTaxiView {
		TextView brand, phone;
		ImageView logo;

		public TextView getBrand() {
			return brand;
		}

		public void setBrand(TextView brand) {
			this.brand = brand;
		}

		public TextView getPhone() {
			return phone;
		}

		public void setPhone(TextView phone) {
			this.phone = phone;
		}

		public ImageView getLogo() {
			return logo;
		}

		public void setLogo(ImageView logo) {
			this.logo = logo;
		}

	}
}
